package com.zhny.project.count.display.controller;

import com.zhny.common.utils.poi.ExcelUtil;
import com.zhny.framework.aspectj.lang.annotation.Log;
import com.zhny.framework.aspectj.lang.enums.BusinessType;
import com.zhny.framework.web.controller.BaseController;
import com.zhny.framework.web.domain.AjaxResult;
import com.zhny.framework.web.page.TableDataInfo;
import com.zhny.project.count.display.domain.Display;
import com.zhny.project.count.display.service.IDisplayService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 算法显示Controller
 * 
 * @author lxh
 * @date 2019-09-24
 */
@Controller
@RequestMapping("/count/display")
public class DisplayController extends BaseController
{
    private String prefix = "count/display";

    @Autowired
    private IDisplayService displayService;

    @RequiresPermissions("count:display:view")
    @GetMapping()
    public String display()
    {
        return prefix + "/display";
    }

    /**
     * 查询算法显示列表
     */
    @RequiresPermissions("count:display:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Display display)
    {
        startPage();
        List<Display> list = displayService.selectDisplayList(display);
        return getDataTable(list);
    }

    /**
     * 导出算法显示列表
     */
    @RequiresPermissions("count:display:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Display display)
    {
        List<Display> list = displayService.selectDisplayList(display);
        ExcelUtil<Display> util = new ExcelUtil<Display>(Display.class);
        return util.exportExcel(list, "display");
    }

    /**
     * 新增算法显示
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存算法显示
     */
    @RequiresPermissions("count:display:add")
    @Log(title = "算法显示", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Display display)
    {
        return toAjax(displayService.insertDisplay(display));
    }

    /**
     * 修改算法显示
     */
    @GetMapping("/edit/{displayKey}")
    public String edit(@PathVariable("displayKey") String displayKey, ModelMap mmap)
    {
        Display display = displayService.selectDisplayById(displayKey);
        mmap.put("display", display);
        return prefix + "/edit";
    }

    /**
     * 修改保存算法显示
     */
    @RequiresPermissions("count:display:edit")
    @Log(title = "算法显示", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Display display)
    {
        return toAjax(displayService.updateDisplay(display));
    }

    /**
     * 删除算法显示
     */
    @RequiresPermissions("count:display:remove")
    @Log(title = "算法显示", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(displayService.deleteDisplayByIds(ids));
    }


    /**
     * 校验ID
     */
    @PostMapping("/checkcontrollerId")
    @ResponseBody
    public String checkcontrollerId(Display display)
    {
        return displayService.checkcontrollerId(display);
    }


    /**
     * 校验Name
     */
    @PostMapping("/checkdisplayName")
    @ResponseBody
    public String checkdisplayName(Display display)
    {
        return displayService.checkdisplayName(display);
    }

}
